package com.gd.iot.energy.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.HMac;
import com.gd.iot.energy.consts.SystemConsts;

/**
 * 密码工具
 *
 * @author kris
 * @date Created at 2020/8/3 17:10
 */
public class PasswordUtil {

    /**
     * hmacsha1 密码生成
     * @param password
     * @return
     */
    public static String generateHmacSHA1Password(String password){
        HMac hMac = SecureUtil.hmacSha1(SystemConsts.PASSWORD_SECRET);
        return hMac.digestHex(password);
    }

    /**
     * 校验密码
     * @param password 密码明文
     * @param sha1Password 加密后的密码
     * @return
     */
    public static boolean validateHmacSHA1Password(String password,String sha1Password){
        return generateHmacSHA1Password(password).equals(sha1Password);
    }
}
